// @license
// Copyright 2024 The Model Explorer Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ==============================================================================

.container {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  border: 1px solid var(--me-surface-variant-color);
  border-radius: 8px;
  overflow: hidden;

  .content {
    width: 100%;
    box-sizing: border-box;
    padding: 24px;
    padding-bottom: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    &.no-models {
      padding-bottom: 24px;
    }
  }

  .title {
    color: var(--me-on-surface-color);
    font-size: 24px;
  }

  .description-container {
    color: var(--me-on-surface-variant-color);
    font-size: 14px;
    margin-top: 8px;

    .description {
      line-height: 20px;

      .tfhub {
        display: inline-block;
        text-decoration: underline;
        text-decoration-color: var(--me-on-surface-variant-color);
        cursor: help;
      }

      .help-trigger {
        display: inline-block;
        margin-right: 6px;
        text-decoration: underline;
        text-decoration-color: var(--me-on-surface-variant-color);
        cursor: help;

        &.external {
          margin-right: 0;
        }
      }

      a {
        color: inherit;
      }
    }

    .custom-extensions {
      margin-top: 16px;

      .section-title {
        display: flex;
        align-items: center;
        gap: 8px;
        font-weight: 500;

        mat-icon {
          font-size: 18px;
          width: 18px;
          height: 18px;
          color: var(--me-on-surface-variant-color);
        }
      }

      .extension-name {
        color: var(--me-on-surface-color);
        display: inline-flex;
        align-items: center;
      }

      .exts {
        display: inline-flex;
        margin-left: 8px;
        gap: 4px;

        .ext {
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 12px;
          padding: 2px 3px;
          border-radius: 4px;
          background-color: var(--me-surface-container-high-color);
          border: 1px solid var(--me-outline-variant-color);
          box-sizing: border-box;
        }
      }

      ul {
        max-height: 200px;
        overflow-y: auto;
        margin-top: 0px;

        .description {
          margin-top: 2px;
          display: inline-block;
          color: var(--me-on-surface-low-color);
        }

        li {
          margin-top: 10px;
        }
      }
    }
  }

  .source-input-container {
    display: flex;
    height: 56px;
    box-sizing: border-box;
    width: 100%;
    margin-top: 8px;
    padding: 8px 0;
    align-items: center;
    flex-shrink: 0;

    &.reverse {
      flex-direction: row-reverse;
    }

    .input-container {
      height: 100%;
      box-sizing: border-box;
      background-color: var(--me-surface-container-high-color);
      border-radius: 99px;
      flex-grow: 1;
      display: flex;
      align-items: center;
      padding-left: 18px;

      input {
        height: 100%;
        flex-grow: 1;
        border: none;
        outline: none;
        background-color: transparent;
        color: var(--me-on-surface-color);
        font-size: 14px;
        margin-right: 16px;
      }

      .btn-add-model-path {
        background-color: var(--me-surface-color);
        border-radius: 99px;
        color: var(--me-link-color);
        height: 40px;
        box-shadow: none;
        border: 1px solid var(--me-surface-variant-color);

        &[disabled] {
          background-color: var(--me-disabled-button-bg-color);
          color: var(--me-disabled-button-color);
        }
      }
    }

    .or-label {
      font-size: 14px;
      margin: 0 20px;
      color: var(--me-on-surface-variant-color);
    }

    .btn-upload {
      height: 100%;
      background-color: var(--me-secondary-container-color);
      border-radius: 99px;
      color: var(--me-on-secondary-container-color);

      &[disabled] {
        background-color: var(--me-disabled-button-bg-color);
        color: var(--me-disabled-button-color);
      }
    }

    .upload-input {
      display: none;
    }
  }

  .model-count-warning {
    color: var(--me-warning-text-color);
    background-color: var(--me-warning-container-color);
    margin: 4px 0;
    width: fit-content;
    padding: 2px 9px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
  }

  .models-table {
    width: 100%;
    color: var(--me-on-surface-color);
    font-size: 14px;
    margin-top: 18px;
    overflow: hidden auto;

    table {
      width: 100%;
      border-spacing: 0;
      border-collapse: collapse;
      padding: 0;

      thead {
        position: sticky;
        top: 0;
        z-index: 100;
        box-shadow: inset 0 -1px 0 var(--me-surface-variant-color);
        background-color: var(--me-surface-color);

        .model-name-col {
          width: 100%;
        }

        .adapter-header {
          display: flex;
          align-items: center;
          gap: 4px;

          .icon-container {
            display: flex;
            align-items: center;
            cursor: pointer;
            opacity: 0.8;

            &:hover {
              opacity: 1;
            }
          }

          mat-icon {
            font-size: 20px;
            width: 20px;
            height: 20px;
            color: var(--me-on-surface-variant-color);
          }
        }
      }

      th {
        height: 49px;
        text-align: left;
        padding: 0;
        font-weight: 500;
      }

      tr {
        height: 49px;
        text-align: left;
        padding: 0;

        &:not(:last-child) {
          border-bottom: 1px solid var(--me-surface-variant-color);
        }
      }

      td {
        padding: 0;
      }

      .model-name-container {
        display: flex;
        align-items: center;
        padding-left: 12px;
        margin-right: 12px;
        word-break: break-all;

        &.disabled {
          pointer-events: none;
        }

        mat-checkbox {
          margin-right: 2px;
        }

        .model-path {
          cursor: pointer;
          line-height: 16px;
          padding: 8px 0;

          &.disabled {
            pointer-events: none;
          }
        }
      }

      .selected-adapter-container {
        display: flex;
        align-items: center;
        justify-content: space-between;
        cursor: pointer;
        height: 48px;
        margin-right: 24px;
        white-space: nowrap;

        &.disabled {
          opacity: 0.5;
          pointer-events: none;
        }

        &:hover mat-icon {
          opacity: 1;
        }

        mat-icon {
          opacity: 0.7;
        }
      }

      .no-supported-adapter-msg {
        color: var(--me-warning-text-color);
        background-color: var(--me-warning-container-color);
        padding: 2px 8px;
        width: fit-content;
        border-radius: 4px;
        font-size: 12px;
        margin-right: 24px;
        white-space: nowrap;
        font-weight: 500;
      }

      .model-status-container {
        display: flex;
        align-items: center;
        margin-right: 32px;

        mat-spinner {
          margin-right: 4px;
        }

        .model-status-label-container {
          font-size: 12px;
          padding: 2px 8px;
          background-color: var(--me-surface-container-high-color);
          display: flex;
          align-items: center;
          justify-content: center;
          width: fit-content;
          border-radius: 4px;
          white-space: nowrap;
          font-weight: 500;

          &.done {
            color: var(--me-success-text-color);
            background-color: var(--me-success-container-color);
          }

          &.error {
            color: var(--me-error-text-color);
            background-color: var(--me-error-container-color);
          }
        }

        .error-info-container {
          width: 20px;
          display: flex;
          align-items: center;
          justify-content: center;
          margin-left: 4px;
          cursor: pointer;

          mat-icon {
            color: var(--me-on-surface-variant-color);
            width: 20px;
            height: 20px;
            font-size: 20px;
          }
        }
      }

      .btn-delete-model-item {
        width: 36px;
        height: 36px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;

        &[disabled] {
          opacity: 0.5;
        }

        ::ng-deep mat-icon {
          font-size: 20px;
          width: 20px;
          height: 20px;
          color: var(--me-on-surface-variant-color);
        }
      }
    }
  }

  .table-action-bar {
    flex-shrink: 0;
    height: 60px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--me-surface-container-high-color);
    padding: 0 24px 0 38px;

    .selection-status {
      display: flex;
      align-items: center;
      font-size: 14px;
      color: var(--me-on-surface-variant-color);

      &.hide {
        visibility: hidden;
      }
    }

    .btn-deselect-all {
      width: 36px;
      height: 36px;
      padding: 0;
      display: flex;
      align-items: center;
      justify-content: center;

      ::ng-deep mat-icon {
        font-size: 20px;
        width: 20px;
        height: 20px;
        color: var(--me-on-surface-variant-color);
      }
    }

    .btn-view-models {
      height: 40px;
      border-radius: 99px;
    }
  }
}

::ng-deep .model-explorer-upload-help-popup {
  padding: 12px;
  font-weight: normal;
  color: var(--me-on-surface-color);
  line-height: 14px;
  font-size: 12px;
  font-family: 'Google Sans Text', Arial, Helvetica, sans-serif;
}

::ng-deep .model-explorer-adapter-help-popup {
  padding: 12px;
  font-weight: normal;
  color: var(--me-on-surface-color);
  line-height: 15px;
  font-size: 12px;
  font-family: 'Google Sans Text', Arial, Helvetica, sans-serif;

  &::ng-deep.bold {
    font-weight: 700;
  }
}

::ng-deep .model-explorer-model-format-help-popup {
  padding: 12px;
  font-weight: normal;
  color: var(--me-on-surface-color);
  line-height: 15px;
  font-size: 12px;
  font-family: 'Google Sans Text', Arial, Helvetica, sans-serif;
  letter-spacing: normal;

  a {
    color: inherit;
  }

  .example {
    margin-top: 8px;
    color: var(--me-on-surface-variant-color);

    ul {
      margin: 4px 0;
      padding-inline-start: 28px;
    }

    li {
      margin-top: 4px;
    }
  }

  .info {
    display: inline-block;
    color: var(--me-warning-text-color);
    background-color: var(--me-warning-container-color);
  }
}

::ng-deep .model-explorer-error-info-popup {
  padding: 12px;
  font-weight: normal;
  background-color: var(--me-surface-container-low-color);
  line-height: 14px;
  font-size: 12px;
  font-family: 'Google Sans Text', Arial, Helvetica, sans-serif;
}

::ng-deep .model-path-autocomplete {
  mat-option {
    min-height: 13px;
    font-size: 13px;
    line-height: 13px;
    padding-top: 5px;
    padding-bottom: 5px;

    &:hover .option-container .mat-icon-container {
      visibility: visible;
    }

    > span {
      width: 100%;
    }

    .option-container {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;
      word-break: break-all;

      .icons-container {
        display: flex;
        align-items: center;
        gap: 4px;
        min-width: 50px;
        justify-content: flex-end;
      }

      .mat-icon-container {
        visibility: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0.6;
        width: 18px;

        &:hover {
          opacity: 1;
        }

        mat-icon {
          font-size: 18px;
          width: 18px;
          height: 18px;
        }
      }
    }
  }
}
